<?php

/**
 * model_staff
 */

class Model_staff extends YOU {

	public function __construct()
	{
        @$this->model->user   	= YOU::loadModel('user');
		parent::__construct();
	}

	/** 读取总数 **/
	public function count()
	{
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_staff`");
		return (int)$row['count'];
	}
	
	
	/** 读取成配置 **/
	public function getIni()
	{
		$staff_lists = $this->getAll();
		foreach ($staff_lists as $key => $value){
			$staff[$value['staff_id']] = $value['staff_name'];
		}

		return $staff;
	}

	/** 读取列表 **/
	public function getAll($field = "*")
	{
		$staff_lists = $this->db->fetchAll("SELECT {$field} FROM `tbl_staff` ");

		return $staff_lists;
	}

	/** 读取信息 **/
	public function getInfo($staff_id, $field = "*")
	{
		$data = $this->db->fetchRow("SELECT {$field} FROM `tbl_staff` WHERE staff_id='{$staff_id}' ");
		
		return $data;
	}

	/** 读取名称根据id **/
	public function getNameById($staff_id)
	{
		$data = $this->getInfo($staff_id, "staff_name");

		return $data['staff_name'];
	}
	/** 根据名字查询多条 **/
	public function getNameMAll($staff_name, $field = "*")//wq 11.21 row->all resource line95
	{
		$staff_lists = $this->db->fetchAll("SELECT {$field} FROM `tbl_staff` WHERE staff_name LIKE '%{$staff_name}%' ");
        $idarr = array();
        foreach ($staff_lists as $key => $value){
            $id = $this->model->user->getIdByType('staff',$value['staff_id']);
            $idarr[] = $id;
        }
        $idarr = array_filter($idarr);
        $ids = implode(',',$idarr);
		return $ids;
	}
	/** 根据名字查询多条(模糊搜索) **/
	public function getNameAll($staff_names, $field = "*")
	{	
		
		$staff_list = $this->db->fetchRow("SELECT {$field} FROM `tbl_staff` WHERE staff_name LIKE '%{$staff_names}%' ");
	
		return $staff_list;
	}
	
}



?>